package com.study.controller.HRcontroller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.study.model.pojo.HRpojo.AppTab;
import com.study.model.pojo.HRpojo.DeptTab;
import com.study.model.pojo.HRpojo.EmpTab;
import com.study.service.HRservice.AppService;

//CrossOrigin 解决跨域
/**
 * @author 大桐桐
 *
 */
@CrossOrigin
@RestController
@RequestMapping("/AppCon")
public class AppController {

	@Autowired
	AppService appService;
	
	/**
	 * 查询
	 * @return
	 */
	@RequestMapping("appFindAll")
	public List<AppTab> findAll(){
		List<AppTab> findAll = appService.findAll();
		System.out.println(findAll.get(0));
		return findAll;
	}
	
	/**
	 * 新增招聘申请
	 * @param apptab
	 * @return
	 * @throws ParseException 
	 */
	@RequestMapping("addApp")
	public List<AppTab> addApp(@RequestBody Map<String, String> map) throws ParseException{
		AppTab apptab = new AppTab();
		
		DeptTab depttab = new DeptTab();
		depttab.setDeptid(3);
		
		EmpTab emptab = new EmpTab();
		emptab.setEmpid("emp20170909002");
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		
		apptab.setDeptTab(depttab);
		System.out.println("1111111");
		
		apptab.setEmpTab(emptab);
		System.out.println(map.get("appemployment"));
		apptab.setAppemployment(df.parse(map.get("appemployment")));
		apptab.setApppost(map.get("apppost"));
		apptab.setAppnum(Integer.parseInt(map.get("appnum")));
		apptab.setPostrequire(map.get("postrequire"));
		apptab.setAppremark(map.get("appremark"));
		apptab.setAppstate(1);
		apptab.setAppdate(new Date(map.get("appdate")));
		
		AppTab addApp = appService.addApp(apptab);
//		return appService.findAll();
		return appService.findAll();
	}
	
	/**
	 * 编辑招聘申请
	 * @param map
	 * @return
	 */
	@RequestMapping("editApp")
	public List<AppTab> editApp(@RequestBody Map<String, String> map) {
		AppTab editApp = appService.editApp(map);
		return appService.findAll();
	}
	
	/**
	 * 前端点击通过按钮，修改审核状态，改为审核通过
	 * @param map
	 * @return
	 */
	@RequestMapping("editAppState2")
	public List<AppTab> editAppState2(@RequestBody Map<String, String> map) {
		System.out.println(map.get("appid"));
		AppTab editAppState2 = appService.editAppState2(map);
		return appService.findAll();
	}
	
	/**
	 * 前端点击通过按钮，修改审核状态，改为审核失败
	 * @param map
	 * @return
	 */
	@RequestMapping("editAppState3")
	public List<AppTab> editAppState3(@RequestBody Map<String, String> map) {
		System.out.println(map.get("appid"));
		AppTab editAppState3 = appService.editAppState3(map);
		return appService.findAll();
	}
	
}
